package com.yanqu.road.dao.impl.activity.foxcard;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;

import com.yanqu.road.entity.activity.foxcard.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class FoxCardConfigDaoImpl extends TempDao {
    private static String getFoxCardBuffConfigSql = "SELECT * FROM t_s_activity_fox_buff WHERE activityId = ?";
    public Map<Integer, FoxCardBuffConfig> getFoxCardBuffConfig(int activityId) {
        Map<Integer, FoxCardBuffConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardBuffConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardBuffConfig config = new FoxCardBuffConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
    private static String getFoxCardCardConfigSql = "SELECT * FROM t_s_activity_fox_card WHERE activityId = ?";
    public Map<Integer, FoxCardEffectCardConfig> getFoxCardEffectCardConfig(int activityId) {
        Map<Integer, FoxCardEffectCardConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardCardConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardEffectCardConfig config = new FoxCardEffectCardConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_chapter")
//    public class FoxCardChapterConfig
    private static String getFoxCardChapterConfigSql = "SELECT * FROM t_s_activity_fox_chapter WHERE activityId = ?";
    public Map<Integer, FoxCardChapterConfig> getFoxCardChapterConfig(int activityId) {
        Map<Integer, FoxCardChapterConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardChapterConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardChapterConfig config = new FoxCardChapterConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_coupon")
//    public class FoxCardCouponConfig
    private static String getFoxCardCouponConfigSql = "SELECT * FROM t_s_activity_fox_coupon WHERE activityId = ?";
    public Map<Integer, FoxCardCouponConfig> getFoxCardCouponConfig(int activityId) {
        Map<Integer, FoxCardCouponConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardCouponConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardCouponConfig config = new FoxCardCouponConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_label")
//    public class FoxCardLabelConfig
    private static String getFoxCardLabelConfigSql = "SELECT * FROM t_s_activity_fox_label WHERE activityId = ?";
    public Map<Integer, FoxCardLabelConfig> getFoxCardLabelConfig(int activityId) {
        Map<Integer, FoxCardLabelConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardLabelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardLabelConfig config = new FoxCardLabelConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_limit")
//    public class FoxCardLimitConfig
    private static String getFoxCardLimitConfigSql = "SELECT * FROM t_s_activity_fox_limit WHERE activityId = ?";
    public Map<Integer, FoxCardLimitConfig> getFoxCardLimitConfig(int activityId) {
        Map<Integer, FoxCardLimitConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardLimitConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardLimitConfig config = new FoxCardLimitConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_lottery")
//    public class FoxCardLotteryConfig
    private static String getFoxCardLotteryConfigSql = "SELECT * FROM t_s_activity_fox_lottery WHERE activityId = ?";
    public Map<Integer, FoxCardLotteryConfig> getFoxCardLotteryConfig(int activityId) {
        Map<Integer, FoxCardLotteryConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardLotteryConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardLotteryConfig config = new FoxCardLotteryConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_lottery_settle")
//    public class FoxCardLotterySettleConfig
    private static String getFoxCardLotterySettleConfigSql = "SELECT * FROM t_s_activity_fox_lottery_settle WHERE activityId = ?";
    public Map<Integer, FoxCardLotterySettleConfig> getFoxCardLotterySettleConfig(int activityId) {
        Map<Integer, FoxCardLotterySettleConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardLotterySettleConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardLotterySettleConfig config = new FoxCardLotterySettleConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_magic_weapon")
//    public class FoxCardMagicWeaponConfig
    private static String getFoxCardMagicWeaponConfigSql = "SELECT * FROM t_s_activity_fox_magicweapon WHERE activityId = ?";
    public Map<Integer, FoxCardMagicWeaponConfig> getFoxCardMagicWeaponConfig(int activityId) {
        Map<Integer, FoxCardMagicWeaponConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardMagicWeaponConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardMagicWeaponConfig config = new FoxCardMagicWeaponConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_round")
//    public class FoxCardRoundConfig
    private static String getFoxCardRoundConfigSql = "SELECT * FROM t_s_activity_fox_round WHERE activityId = ?";
    public Map<Integer, FoxCardRoundConfig> getFoxCardRoundConfig(int activityId) {
        Map<Integer, FoxCardRoundConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardRoundConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardRoundConfig config = new FoxCardRoundConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_shop")
//    public class FoxCardShopConfig
    private static String getFoxCardShopConfigSql = "SELECT * FROM t_s_activity_fox_shop WHERE activityId = ?";
    public Map<Integer, FoxCardShopConfig> getFoxCardShopConfig(int activityId) {
        Map<Integer, FoxCardShopConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardShopConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardShopConfig config = new FoxCardShopConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_sorcery")
//    public class FoxCardSorceryConfig
    private static String getFoxCardSorceryConfigSql = "SELECT * FROM t_s_activity_fox_sorcery WHERE activityId = ?";
    public Map<Integer, FoxCardSorceryConfig> getFoxCardSorceryConfig(int activityId) {
        Map<Integer, FoxCardSorceryConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardSorceryConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardSorceryConfig config = new FoxCardSorceryConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_spell")
//    public class FoxCardSpellConfig
    private static String getFoxCardSpellConfigSql = "SELECT * FROM t_s_activity_fox_spell WHERE activityId = ?";
    public Map<Integer, FoxCardSpellConfig> getFoxCardSpellConfig(int activityId) {
        Map<Integer, FoxCardSpellConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardSpellConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardSpellConfig config = new FoxCardSpellConfig(rs);
                dataMap.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

//    @FieldTypeAnnotation(tableName = "t_s_activity_fox_treeLevel")
//    public class FoxCardTreeLevelConfig
    private static String getFoxCardTreeLevelConfigSql = "SELECT * FROM t_s_activity_fox_treelevel WHERE activityId = ?";
    public Map<Integer, FoxCardTreeLevelConfig> getFoxCardTreeLevelConfig(int activityId) {
        Map<Integer, FoxCardTreeLevelConfig>  dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFoxCardTreeLevelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FoxCardTreeLevelConfig config = new FoxCardTreeLevelConfig(rs);
                dataMap.put(config.getLevel(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
